public class Answer1 {
    //最长回文子串
    //https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af?tpId=182&tqId=34752&ru=/exam/oj
    public static int getLongestPalindrome (String A) {
        int n = A.length();
        int ret = 0;
        for (int i = 0, left = 0, right = 0; i < n; i++) {
            // 奇数
            left = i-1;right=i+1;
            while (left >= 0 && right < n && A.charAt(left) == A.charAt(right)) {
                left--;
                right++;
            }
            ret = Math.max(ret, right - left - 1);
            // 偶数
            left=i-1;right=i;
            while (left >= 0 && right < n && A.charAt(left) == A.charAt(right)) {
                left--;
                right++;
            }
            ret = Math.max(ret, right - left - 1);
        }

        return ret;
    }

    public static void main(String[] args) {
        System.out.println(getLongestPalindrome("abbba"));
    }
}
